<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.min.js"></script>
</head>
<body>

<!--     <div id="demo">
    <button v-on:click="show = !show">
        Toggle
    </button>
    <transition name="fade">
        <p v-if="show">hello</p>
    </transition>
</div>

<script>
    new Vue({
        el: '#demo',
        data: {
            show: true
        }
    })
</script>
<style>
    .fade-enter-active, .fade-leave-active {
        transition: opacity .5s
    }
    .fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
        opacity: 0
    }
</style> -->

    <div id="list-demo" class="demo">
      <button v-on:click="add">Add</button>
      <button v-on:click="remove">Remove</button>
      <transition-group name="list" tag="a">
        <span v-for="item in items" v-bind:key="item" class="list-item">
          {{ item }}
        </span>
      </transition-group>
    </div>

    <script>
        new Vue({
          el: '#list-demo',
          data: {
            items: [1,2,3,4,5,6,7,8,9],
            nextNum: 10
          },
          methods: {
            randomIndex: function () {
              return Math.floor(Math.random() * this.items.length)
            },
            add: function () {
              // this.items.splice(this.randomIndex(), 0, this.nextNum++)
              var arr = [1,2,3,4,5,6]
              arr.forEach( ( item, index ) => {
                setTimeout( _ => {
                    this.items.push( item )                    
                }, index * 100 )
              } )

              console.log( this.items )
            },
            remove: function () {
              this.items.splice(this.randomIndex(), 1)
            },
          }
        })
    </script>

    <style>
        .list-item {
          display: inline-block;
          margin-right: 10px;
        }
        .list-enter-active, .list-leave-active {
          transition: all 1s;
        }
        .list-enter, .list-leave-active {
          opacity: 0;
          transform: translateY(30px);
        }
    </style>

</body>
</html>